package controllers;

import java.util.ArrayList;
import java.util.List;

import org.h2.util.StringUtils;

public class TableRequest {
	public String sEcho;
	public int iColumns;
	public String sColumns;
	public int iDisplayStart;
	public int iDisplayLength;
	public String mDataProp_0;
	public String mDataProp_1;
	public String mDataProp_2;
	public String mDataProp_3;
	public String mDataProp_4;
	public String mDataProp_5;
	public String mDataProp_6;
	public String mDataProp_7;
	public String mDataProp_8;
	public String mDataProp_9;
	public String mDataProp_10;
	public String mDataProp_11;
	public String mDataProp_12;
	public String mDataProp_13;
	public String mDataProp_14;
	public String mDataProp_15;
	public String mDataProp_16;
	public String mDataProp_17;
	public String mDataProp_18;
	public String mDataProp_19;
	public String mDataProp_20;
	public String mDataProp_21;
	public String mDataProp_22;
	public String mDataProp_23;
	public String mDataProp_24;
	public String mDataProp_25;
	public String mDataProp_26;
	public String mDataProp_27;
	public String mDataProp_28;
	public String mDataProp_29;
	public String mDataProp_30;
	public String mDataProp_31;
	public String mDataProp_32;
	public String mDataProp_33;
	public String mDataProp_34;
	public String mDataProp_35;
	public String mDataProp_36;
	public String mDataProp_37;
	public String mDataProp_38;
	public String mDataProp_39;
	public String sSearch;
	public boolean bRegex;
	public String sSearch_0;
	public boolean bRegex_0;
	public boolean bSearchable_0;
	public String sSearch_1;
	public boolean bRegex_1;
	public boolean bSearchable_1;
	public String sSearch_2;
	public boolean bRegex_2;
	public boolean bSearchable_2;
	public String sSearch_3;
	public boolean bRegex_3;
	public boolean bSearchable_3;
	public String sSearch_4;
	public boolean bRegex_4;
	public boolean bSearchable_4;
	public String sSearch_5;
	public boolean bRegex_5;
	public boolean bSearchable_5;
	public String sSearch_6;
	public boolean bRegex_6;
	public boolean bSearchable_6;
	public String sSearch_7;
	public boolean bRegex_7;
	public boolean bSearchable_7;
	public String sSearch_8;
	public boolean bRegex_8;
	public boolean bSearchable_8;
	public String sSearch_9;
	public boolean bRegex_9;
	public boolean bSearchable_9;
	public String sSearch_10;
	public boolean bRegex_10;
	public boolean bSearchable_10;
	public String sSearch_11;
	public boolean bRegex_11;
	public boolean bSearchable_11;
	public String sSearch_12;
	public boolean bRegex_12;
	public boolean bSearchable_12;
	public String sSearch_13;
	public boolean bRegex_13;
	public boolean bSearchable_13;
	public String sSearch_14;
	public boolean bRegex_14;
	public boolean bSearchable_14;
	public String sSearch_15;
	public boolean bRegex_15;
	public boolean bSearchable_15;
	public String sSearch_16;
	public boolean bRegex_16;
	public boolean bSearchable_16;
	public String sSearch_17;
	public boolean bRegex_17;
	public boolean bSearchable_17;
	public String sSearch_18;
	public boolean bRegex_18;
	public boolean bSearchable_18;
	public String sSearch_19;
	public boolean bRegex_19;
	public boolean bSearchable_19;
	public String sSearch_20;
	public boolean bRegex_20;
	public boolean bSearchable_20;
	public String sSearch_21;
	public boolean bRegex_21;
	public boolean bSearchable_21;
	public String sSearch_22;
	public boolean bRegex_22;
	public boolean bSearchable_22;
	public String sSearch_23;
	public boolean bRegex_23;
	public boolean bSearchable_23;
	public String sSearch_24;
	public boolean bRegex_24;
	public boolean bSearchable_24;
	public String sSearch_25;
	public boolean bRegex_25;
	public boolean bSearchable_25;
	public String sSearch_26;
	public boolean bRegex_26;
	public boolean bSearchable_26;
	public String sSearch_27;
	public boolean bRegex_27;
	public boolean bSearchable_27;
	public String sSearch_28;
	public boolean bRegex_28;
	public boolean bSearchable_28;
	public String sSearch_29;
	public boolean bRegex_29;
	public boolean bSearchable_29;
	public String sSearch_30;
	public boolean bRegex_30;
	public boolean bSearchable_30;
	public String sSearch_31;
	public boolean bRegex_31;
	public boolean bSearchable_31;
	public String sSearch_32;
	public boolean bRegex_32;
	public boolean bSearchable_32;
	public String sSearch_33;
	public boolean bRegex_33;
	public boolean bSearchable_33;
	public String sSearch_34;
	public boolean bRegex_34;
	public boolean bSearchable_34;
	public String sSearch_35;
	public boolean bRegex_35;
	public boolean bSearchable_35;
	public String sSearch_36;
	public boolean bRegex_36;
	public boolean bSearchable_36;
	public String sSearch_37;
	public boolean bRegex_37;
	public boolean bSearchable_37;
	public String sSearch_38;
	public boolean bRegex_38;
	public boolean bSearchable_38;
	public String sSearch_39;
	public boolean bRegex_39;
	public boolean bSearchable_39;
	
	public int iSortCol_0;
	public String sSortDir_0;
	public int iSortingCols;
	public boolean bSortable_0;
	public boolean bSortable_1;
	public boolean bSortable_2;
	public boolean bSortable_3;
	public boolean bSortable_4;
	public boolean bSortable_5;
	public boolean bSortable_6;
	public boolean bSortable_7;
	public boolean bSortable_8;
	public boolean bSortable_9;
	public boolean bSortable_10;
	public boolean bSortable_11;
	public boolean bSortable_12;
	public boolean bSortable_13;
	public boolean bSortable_14;
	public boolean bSortable_15;
	public boolean bSortable_16;
	public boolean bSortable_17;
	public boolean bSortable_18;
	public boolean bSortable_19;
	public boolean bSortable_20;
	public boolean bSortable_21;
	public boolean bSortable_22;
	public boolean bSortable_23;
	public boolean bSortable_24;
	public boolean bSortable_25;
	public boolean bSortable_26;
	public boolean bSortable_27;
	public boolean bSortable_28;
	public boolean bSortable_29;
	public boolean bSortable_30;
	public boolean bSortable_31;
	public boolean bSortable_32;
	public boolean bSortable_33;
	public boolean bSortable_34;
	public boolean bSortable_35;
	public boolean bSortable_36;
	public boolean bSortable_37;
	public boolean bSortable_38;
	public boolean bSortable_39;
	
	public class StringPair {
		public StringPair(String colum, String search) {
			this.str1 = colum;
			this.str2 = search;
		}
		public String str1;
		public String str2;
	}
	
	public List<String> getColumNames() {
		List<String> colums = new ArrayList<String>();
		if (!StringUtils.isNullOrEmpty(mDataProp_0)) {
			colums.add(mDataProp_0);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_1)) {
			colums.add(mDataProp_1);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_2)) {
			colums.add(mDataProp_2);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_3)) {
			colums.add(mDataProp_3);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_4)) {
			colums.add(mDataProp_4);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_5)) {
			colums.add(mDataProp_5);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_6)) {
			colums.add(mDataProp_6);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_7)) {
			colums.add(mDataProp_7);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_8)) {
			colums.add(mDataProp_8);
		}	
		if (!StringUtils.isNullOrEmpty(mDataProp_9)) {
			colums.add(mDataProp_9);
		}	
		if (!StringUtils.isNullOrEmpty(mDataProp_10)) {
			colums.add(mDataProp_10);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_11)) {
			colums.add(mDataProp_11);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_12)) {
			colums.add(mDataProp_12);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_13)) {
			colums.add(mDataProp_13);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_14)) {
			colums.add(mDataProp_14);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_15)) {
			colums.add(mDataProp_15);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_16)) {
			colums.add(mDataProp_16);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_17)) {
			colums.add(mDataProp_17);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_18)) {
			colums.add(mDataProp_18);
		}	
		if (!StringUtils.isNullOrEmpty(mDataProp_19)) {
			colums.add(mDataProp_19);
		}	
		
		if (!StringUtils.isNullOrEmpty(mDataProp_20)) {
			colums.add(mDataProp_20);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_21)) {
			colums.add(mDataProp_21);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_22)) {
			colums.add(mDataProp_22);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_23)) {
			colums.add(mDataProp_23);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_24)) {
			colums.add(mDataProp_24);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_25)) {
			colums.add(mDataProp_25);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_26)) {
			colums.add(mDataProp_26);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_27)) {
			colums.add(mDataProp_27);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_28)) {
			colums.add(mDataProp_28);
		}	
		if (!StringUtils.isNullOrEmpty(mDataProp_29)) {
			colums.add(mDataProp_28);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_30)) {
			colums.add(mDataProp_30);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_31)) {
			colums.add(mDataProp_31);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_32)) {
			colums.add(mDataProp_32);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_33)) {
			colums.add(mDataProp_33);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_34)) {
			colums.add(mDataProp_34);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_35)) {
			colums.add(mDataProp_35);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_36)) {
			colums.add(mDataProp_36);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_37)) {
			colums.add(mDataProp_37);
		}
		if (!StringUtils.isNullOrEmpty(mDataProp_38)) {
			colums.add(mDataProp_38);
		}	
		if (!StringUtils.isNullOrEmpty(mDataProp_39)) {
			colums.add(mDataProp_39);
		}	
		return colums;
	}
	
	public List<StringPair> getSearchPairs() {
		List<StringPair> list = new ArrayList<StringPair>();
		if (!StringUtils.isNullOrEmpty(sSearch_0)) {
			list.add(new StringPair(mDataProp_0, sSearch_0));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_1)) {
			list.add(new StringPair(mDataProp_1, sSearch_1));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_2)) {
			list.add(new StringPair(mDataProp_2, sSearch_2));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_3)) {
			list.add(new StringPair(mDataProp_3, sSearch_3));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_4)) {
			list.add(new StringPair(mDataProp_4, sSearch_4));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_5)) {
			list.add(new StringPair(mDataProp_5, sSearch_5));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_6)) {
			list.add(new StringPair(mDataProp_6, sSearch_6));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_7)) {
			list.add(new StringPair(mDataProp_7, sSearch_7));
		}
		
		if (!StringUtils.isNullOrEmpty(sSearch_8)) {
			list.add(new StringPair(mDataProp_8, sSearch_8));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_9)) {
			list.add(new StringPair(mDataProp_9, sSearch_9));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_10)) {
			list.add(new StringPair(mDataProp_10, sSearch_10));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_11)) {
			list.add(new StringPair(mDataProp_11, sSearch_11));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_12)) {
			list.add(new StringPair(mDataProp_12, sSearch_12));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_13)) {
			list.add(new StringPair(mDataProp_13, sSearch_13));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_14)) {
			list.add(new StringPair(mDataProp_14, sSearch_14));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_15)) {
			list.add(new StringPair(mDataProp_15, sSearch_15));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_16)) {
			list.add(new StringPair(mDataProp_16, sSearch_16));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_17)) {
			list.add(new StringPair(mDataProp_17, sSearch_17));
		}
		
		if (!StringUtils.isNullOrEmpty(sSearch_18)) {
			list.add(new StringPair(mDataProp_18, sSearch_18));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_19)) {
			list.add(new StringPair(mDataProp_19, sSearch_19));
		}
		
		if (!StringUtils.isNullOrEmpty(sSearch_20)) {
			list.add(new StringPair(mDataProp_20, sSearch_20));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_21)) {
			list.add(new StringPair(mDataProp_21, sSearch_21));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_22)) {
			list.add(new StringPair(mDataProp_22, sSearch_22));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_23)) {
			list.add(new StringPair(mDataProp_23, sSearch_23));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_24)) {
			list.add(new StringPair(mDataProp_24, sSearch_24));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_25)) {
			list.add(new StringPair(mDataProp_25, sSearch_25));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_26)) {
			list.add(new StringPair(mDataProp_26, sSearch_26));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_27)) {
			list.add(new StringPair(mDataProp_27, sSearch_27));
		}
		
		if (!StringUtils.isNullOrEmpty(sSearch_28)) {
			list.add(new StringPair(mDataProp_28, sSearch_28));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_29)) {
			list.add(new StringPair(mDataProp_29, sSearch_29));
		}
		
		if (!StringUtils.isNullOrEmpty(sSearch_30)) {
			list.add(new StringPair(mDataProp_30, sSearch_30));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_31)) {
			list.add(new StringPair(mDataProp_31, sSearch_31));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_32)) {
			list.add(new StringPair(mDataProp_32, sSearch_32));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_33)) {
			list.add(new StringPair(mDataProp_33, sSearch_33));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_34)) {
			list.add(new StringPair(mDataProp_34, sSearch_34));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_35)) {
			list.add(new StringPair(mDataProp_35, sSearch_35));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_36)) {
			list.add(new StringPair(mDataProp_36, sSearch_36));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_37)) {
			list.add(new StringPair(mDataProp_37, sSearch_37));
		}
		
		if (!StringUtils.isNullOrEmpty(sSearch_38)) {
			list.add(new StringPair(mDataProp_38, sSearch_38));
		}
		if (!StringUtils.isNullOrEmpty(sSearch_39)) {
			list.add(new StringPair(mDataProp_39, sSearch_39));
		}
		
		return list;
	}
	
	public String[] getSearchColums() {
		List<StringPair> p = getSearchPairs();
		String[] r = new String[p.size()];
		for(int i=0; i<r.length; i++) {
			r[i] = p.get(i).str1;
		}
		return r;
	}
	
	public String[] getSearchStrings() {
		List<StringPair> p = getSearchPairs();
		String[] r = new String[p.size()];
		for(int i=0; i<r.length; i++) {
			r[i] = p.get(i).str2;
		}
		return r;
	}
	
	public StringPair getSortPair() {
		StringPair p = null;
		if (iSortingCols >= 1) {
			return new StringPair(getColumNames().get(iSortCol_0), sSortDir_0);
		}	
		else {
			return new StringPair(getColumNames().get(0), "asc"); //默认按第一个字段进行排序
		}
	}
}
